<script src="common.js"></script>
<h1 id="status">Page C</h1>
<div style="display:none" id="pageToScriptTunnel"></div>
<div style="display:none" id="scriptToPageTunnel"></div>

<script>
var backgroundWindow;

window.onload = function() {
  setupScriptTunnel();
  // Note we are using a different window name than a.html so this should open
  // a different background page.
  backgroundWindow = window.open('bg.html', 'bg2', 'background');
  if (backgroundWindow) {
    setStatus('background page opened');
  } else {
    notifyBackgroundPagePermissionDenied();
    setStatus('background page permission denied');
  }
}

function onBackgroundPageLoaded() {
  if (!backgroundWindow.checkAndIncrementCounter(0)) {
    notifyCounterError();
    return;
  }

  setStatus('background page loaded');
  notifyBackgroundPageLoaded();
}
</script>
